#encoding:utf-8
from flask import Blueprint

from flask_restful import Api,Resource,fields,marshal_with
from models import Article
article_bp = Blueprint('article',__name__,url_prefix='/article')

api = Api(article_bp)

# @article_bp.route('/')
# def get(self):
#
class ArticleView(Resource):
    resource_fields = {
        'article_title': fields.String(attribute='title'),
        'content': fields.String,
        'author':fields.Nested(
            {
                'username':fields.String,
                'password':fields.String,
            }
        ),
        'tags':fields.List(fields.Nested({
            'name':fields.String,
        }))
    }

    @marshal_with(resource_fields)
    def get(self, article_id):
        article = Article.query.get(article_id)
        return article
api.add_resource(ArticleView,'/<article_id>/',endpoint="article")
#如果你不写endpoint url_for 用的话就是视图的小写

